﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;

namespace IYAKASAPortal.Tools
{
    /// <summary>
    /// AjaxClassTool 的摘要说明
    /// </summary>
    public class AjaxClassTool : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            StringBuilder _strContent = new StringBuilder();
            if (_strContent.Length == 0)
            {
                string _strAction = context.Request.Params["action"];
                if (string.IsNullOrEmpty(_strAction))
                {
                    _strContent.Append("{\"msg\": \"0\", \"msgbox\": \"禁止访问！\",\"rows\": []}");
                }
                else
                {
                    switch (_strAction.Trim().ToLower())
                    {
                        case "getipstr":
                            _strContent.Append(GetServiceIP());
                            break;
                        default: break;
                    }
                }
            }
            context.Response.Write(_strContent.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private string GetServiceIP()
        {
            string ipStr = string.Empty;

            CONST_DEFINE_WEB_BLL bll = new CONST_DEFINE_WEB_BLL();
            DataTable dt = new DataTable();
            bll.GetModelList(ref dt, " Name = 'DBAddress'");
            if (dt.Rows.Count > 0)
            {              
                ipStr =   dt.Rows[0]["ValueOfName"] == DBNull.Value ? string.Empty : Convert.ToString(dt.Rows[0]["ValueOfName"]);
            }
            return ipStr;
        }


        private void PrintReport()
        {
        }
    }
}